var api = require('../../utils/api.js');

Page({
  data: {
    items: [
      { name: 'A1', value: '大型客车' },
      {name: 'A2', value: '牵引车' },
      { name: 'A3', value: '城市公交车' },
      { name: 'B1', value: '中型客车' },
      { name: 'B2', value: '大型货车' },
      { name: 'C1', value: '小型汽车', checked: 'true' },
      { name: 'C2', value: '小型自动挡汽车' },
      { name: 'C3', value: '低速载货汽车' },
      { name: 'D', value: '普通三轮摩托车' },
      { name: 'E', value: '普通二轮摩托车' },
      { name: 'F', value: '轻便摩托车' },
    ],
    type:'C1'
  },
  radioChange: function (e) {
    this.data.type = e.detail.value;
  },

  getUserInfo: function (e) {
    var user_info = e.detail.userInfo;
    if (user_info) {
      wx.showLoading({
        mask :true,
        title : '初始化中',
      })

      var that = this;
      var type = this.data.type;
      wx.setStorageSync('hasGetUserInfo', 1);
      wx.setStorageSync('user_info', user_info);
      wx.setStorageSync('type',type);

      api.get({
        url: 'Login/addUser',
        data: {
          type: type,
          'encrypted_data': e.detail.encryptedData,
          'iv': e.detail.iv,
          'raw_data': e.detail.rawData,
          'signature': e.detail.signature
        },
        success: res => {
          if(res.code == 1){
            wx.redirectTo({
               url: '/pages/index/index',
            })
          }
          // if (res.question_list_1 && res.question_list_1){
          //   wx.setStorageSync('type',type);
          //   wx.setStorageSync(type+'_question_list_1', res.question_list_1);
          //   wx.setStorageSync(type+'_question_list_4', res.question_list_4)
          //   wx.redirectTo({
          //     url: '/pages/index/index',
          //   })
          // }
        },
      });
    } else {
      wx.showModal({
        title: '进入失败',
        showCancel: false,
        content: '请允许授权',
        success: function (res) {
        }
      })
    }

  }
})
